//
//  QueryViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/7/8.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "QueryViewController.h"
//车牌输入框
#import "CodeView.h"

@interface QueryViewController ()
<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UIButton *queryButton;
@property (strong, nonatomic) IBOutlet UILabel *regionLabel;
@property (strong, nonatomic) CodeView *licensePlateLabel;//车牌输入框
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSArray *regionArray;

@end

@implementation QueryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initViewLayout];
}

- (void)initViewLayout{
    
    [self adaptiveViewLayout:self.view];
    self.view.backgroundColor = [UIColor colorWithWhite:0.957 alpha:1.000];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    self.scroview.contentSize = flexibleSize(CGSizeMake(0, 505),NO);
    self.queryButton.layer.cornerRadius = 20*VerticalRatio();
    
    self.licensePlateLabel = [[CodeView alloc] initWithFrame:flexibleFrame(CGRectMake(50, 41, 270, 40), NO)
                                                         num:6
                                                   lineColor:[UIColor colorWithWhite:0.251 alpha:1.000]
                                                    textFont:15];
    
    //下划线
    self.licensePlateLabel.hasUnderLine = NO;
    //分割线
    self.licensePlateLabel.hasSpaceLine = YES;
    
    //输入风格
    self.licensePlateLabel.codeType = CodeViewTypeCustom;
    [self.scroview addSubview:self.licensePlateLabel];
    
    
    self.tableView.frame = flexibleFrame(CGRectMake(0 , 145, 50, 200), NO);
    self.tableView.hidden = YES;
}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark - 车牌归属地
- (IBAction)region:(UIButton *)sender {
    self.tableView.hidden = sender.selected;
    sender.selected = !sender.selected;
}

#pragma mark - 查询费用
- (IBAction)query:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"PayCost"];
    [self.navigationController   pushViewController:page animated:YES];
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

//定义 UITableView cell 的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 34;
}

//定义 UITableView cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40*VerticalRatio();
}

//定义 UITableView cell 展示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];
    if (!cell) {
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"identifier"];
    }
    cell.selectionStyle = NO;
    
    for (UIView *view in cell.subviews) {
        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    
    UILabel *backgdLabel = [[UILabel alloc] init];
    backgdLabel.backgroundColor = [UIColor colorWithWhite:0.565 alpha:1.000];
    backgdLabel.frame = flexibleFrame(CGRectMake(0, 39, 50, 1), NO);
    [cell addSubview:backgdLabel];
    
    
    UILabel * label = [[UILabel alloc] init];
    label.frame = flexibleFrame(CGRectMake(0, 10, 50, 20), NO);
    label.font = [UIFont systemFontOfSize:15];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor colorWithWhite:0.251 alpha:1.000];
    
    [cell addSubview:label];
    label.text = self.regionArray[indexPath.row];
    
    
    return cell;
}

//定义 UITableView cell 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.regionLabel.text = self.regionArray[indexPath.row];
    self.tableView.hidden = YES;
}

#pragma mark - Custom Accessor
- (NSArray *)regionArray {
    if (!_regionArray) {
        _regionArray = [NSArray array];
        _regionArray = @[@"渝",@"川",@"鄂",@"湘",@"贵",@"黔",@"京",@"津",@"沪",@"蒙",@"新",@"藏",@"宁",@"桂",@"陕",@"滇",@"甘",@"琼",@"粤",@"赣",@"闽",@"浙",@"皖",@"苏",@"豫",@"鲁",@"青",@"冀",@"晋",@"辽",@"吉",@"黑",@"澳",@"港"];
    }
    return _regionArray;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

@end
